Conversation
Solution to 8 tasks. Some code lacks formatting. Will probably be fixed in future versions.
| #include "solution.hpp" | ||
|
|
||
| int main() { | ||
| std::cout << (BinarySearchGEQ({1, 2, 3, 4, 5}, 1, 0, 4) == 0) << std::endl; |
There was a problem hiding this comment.
warning: do not use 'std::endl' with streams; use '\n' instead [performance-avoid-endl]
| std::cout << (BinarySearchGEQ({1, 2, 3, 4, 5}, 1, 0, 4) == 0) << std::endl; | |
| std::cout << (BinarySearchGEQ({1, 2, 3, 4, 5}, 1, 0, 4) == 0) << '\n'; |
| int main() { | ||
| std::cout << (BinarySearchGEQ({1, 2, 3, 4, 5}, 1, 0, 4) == 0) << std::endl; | ||
| std::cout << (BinarySearchGEQ({1, 2, 3, 4, 5}, 5, 0, 4) == 4) | ||
| << std::endl; // Stack [] |
There was a problem hiding this comment.
warning: do not use 'std::endl' with streams; use '\n' instead [performance-avoid-endl]
| << std::endl; // Stack [] | |
| << '\n'; // Stack [] |
|
|
||
| for (unsigned int repeation = 0; repeation < 1000; ++repeation) { | ||
| constexpr unsigned int N = 1000; | ||
| std::array<int, N> min; |
There was a problem hiding this comment.
warning: uninitialized record type: 'min' [cppcoreguidelines-pro-type-member-init]
| std::array<int, N> min; | |
| std::array<int, N> min{}; |
| ASSERT_EQ(min[0], mstack.GetMin()); // forward pass - zero | ||
| for (unsigned int i = 1; i < N; ++i) { | ||
| int value = dist(rng); | ||
|
|
There was a problem hiding this comment.
warning: do not use array subscript when the index is not an integer constant expression [cppcoreguidelines-pro-bounds-constant-array-index]
min[i] = std::min(min[i - 1], value);
^| ASSERT_EQ(min[0], mstack.GetMin()); // forward pass - zero | ||
| for (unsigned int i = 1; i < N; ++i) { | ||
| int value = dist(rng); | ||
|
|
There was a problem hiding this comment.
warning: do not use array subscript when the index is not an integer constant expression [cppcoreguidelines-pro-bounds-constant-array-index]
min[i] = std::min(min[i - 1], value);
^| return heapsort_inplace(arr); | ||
| } | ||
|
|
||
| inline void heapify(std::vector<int>& arr, uint I, uint L) { |
There was a problem hiding this comment.
warning: function 'heapify' can be made static or moved into an anonymous namespace to enforce internal linkage [misc-use-internal-linkage]
| inline void heapify(std::vector<int>& arr, uint I, uint L) { | |
| inline static void heapify(std::vector<int>& arr, uint I, uint L) { |
|
|
||
| inline void heapify(std::vector<int>& arr, uint I, uint L) { | ||
| uint next = I; | ||
| do { |
There was a problem hiding this comment.
warning: avoid do-while loops [cppcoreguidelines-avoid-do-while]
do {
^|
|
||
| sortings::qsort_inplace(arr); | ||
|
|
||
| int target_res = (1 << std::popcount(i)) - 1; |
There was a problem hiding this comment.
warning: no member named 'popcount' in namespace 'std'; did you mean '__popcount'? [clang-diagnostic-error]
| int target_res = (1 << std::popcount(i)) - 1; | |
| int target_res = (1 << std::__popcount(i)) - 1; |
Additional context
/usr/include/c++/13/bit:288: '__popcount' declared here
__popcount(_Tp __x) noexcept
^|
|
||
| for (uint j = 0; j < 16; ++j) actual_res = (actual_res << 1) | arr[j]; | ||
|
|
||
| ASSERT_EQ(std::format("{:016b}", target_res), |
There was a problem hiding this comment.
warning: no member named 'format' in namespace 'std' [clang-diagnostic-error]
ASSERT_EQ(std::format("{:016b}", target_res),
^Additional context
/usr/include/gtest/gtest.h:1897: expanded from macro 'ASSERT_EQ'
#define ASSERT_EQ(val1, val2) GTEST_ASSERT_EQ(val1, val2)
^/usr/include/gtest/gtest.h:1881: expanded from macro 'GTEST_ASSERT_EQ'
ASSERT_PRED_FORMAT2(::testing::internal::EqHelper::Compare, val1, val2)
^/usr/include/gtest/gtest_pred_impl.h:147: expanded from macro 'ASSERT_PRED_FORMAT2'
GTEST_PRED_FORMAT2_(pred_format, v1, v2, GTEST_FATAL_FAILURE_)
^/usr/include/gtest/gtest_pred_impl.h:133: expanded from macro 'GTEST_PRED_FORMAT2_'
GTEST_ASSERT_(pred_format(#v1, #v2, v1, v2), on_failure)
^/usr/include/gtest/gtest_pred_impl.h:78: expanded from macro 'GTEST_ASSERT_'
if (const ::testing::AssertionResult gtest_ar = (expression)) \
^| for (uint j = 0; j < 16; ++j) actual_res = (actual_res << 1) | arr[j]; | ||
|
|
||
| ASSERT_EQ(std::format("{:016b}", target_res), | ||
| std::format("{:016b}", actual_res)) |
There was a problem hiding this comment.
warning: no member named 'format' in namespace 'std' [clang-diagnostic-error]
std::format("{:016b}", actual_res))
^Additional context
/usr/include/gtest/gtest.h:1897: expanded from macro 'ASSERT_EQ'
#define ASSERT_EQ(val1, val2) GTEST_ASSERT_EQ(val1, val2)
^/usr/include/gtest/gtest.h:1881: expanded from macro 'GTEST_ASSERT_EQ'
ASSERT_PRED_FORMAT2(::testing::internal::EqHelper::Compare, val1, val2)
^/usr/include/gtest/gtest_pred_impl.h:147: expanded from macro 'ASSERT_PRED_FORMAT2'
GTEST_PRED_FORMAT2_(pred_format, v1, v2, GTEST_FATAL_FAILURE_)
^/usr/include/gtest/gtest_pred_impl.h:133: expanded from macro 'GTEST_PRED_FORMAT2_'
GTEST_ASSERT_(pred_format(#v1, #v2, v1, v2), on_failure)
^/usr/include/gtest/gtest_pred_impl.h:78: expanded from macro 'GTEST_ASSERT_'
if (const ::testing::AssertionResult gtest_ar = (expression)) \
^Fixed first task random test fail
|
|
||
| ASSERT_EQ(std::format("{:016b}", target_res), | ||
| std::format("{:016b}", actual_res)) | ||
| << std::format("sorting failed on binary pattern {} {:016b}", i, i); |
There was a problem hiding this comment.
warning: no member named 'format' in namespace 'std' [clang-diagnostic-error]
<< std::format("sorting failed on binary pattern {} {:016b}", i, i);
^|
|
||
| sortings::heapsort_inplace(arr); | ||
|
|
||
| int target_res = (1 << std::popcount(i)) - 1; |
There was a problem hiding this comment.
warning: no member named 'popcount' in namespace 'std'; did you mean '__popcount'? [clang-diagnostic-error]
| int target_res = (1 << std::popcount(i)) - 1; | |
| int target_res = (1 << std::__popcount(i)) - 1; |
Additional context
/usr/include/c++/13/bit:288: '__popcount' declared here
__popcount(_Tp __x) noexcept
^|
|
||
| for (uint j = 0; j < 16; ++j) actual_res = (actual_res << 1) | arr[j]; | ||
|
|
||
| ASSERT_EQ(std::format("{:016b}", target_res), |
There was a problem hiding this comment.
warning: no member named 'format' in namespace 'std' [clang-diagnostic-error]
ASSERT_EQ(std::format("{:016b}", target_res),
^Additional context
/usr/include/gtest/gtest.h:1897: expanded from macro 'ASSERT_EQ'
#define ASSERT_EQ(val1, val2) GTEST_ASSERT_EQ(val1, val2)
^/usr/include/gtest/gtest.h:1881: expanded from macro 'GTEST_ASSERT_EQ'
ASSERT_PRED_FORMAT2(::testing::internal::EqHelper::Compare, val1, val2)
^/usr/include/gtest/gtest_pred_impl.h:147: expanded from macro 'ASSERT_PRED_FORMAT2'
GTEST_PRED_FORMAT2_(pred_format, v1, v2, GTEST_FATAL_FAILURE_)
^/usr/include/gtest/gtest_pred_impl.h:133: expanded from macro 'GTEST_PRED_FORMAT2_'
GTEST_ASSERT_(pred_format(#v1, #v2, v1, v2), on_failure)
^/usr/include/gtest/gtest_pred_impl.h:78: expanded from macro 'GTEST_ASSERT_'
if (const ::testing::AssertionResult gtest_ar = (expression)) \
^| for (uint j = 0; j < 16; ++j) actual_res = (actual_res << 1) | arr[j]; | ||
|
|
||
| ASSERT_EQ(std::format("{:016b}", target_res), | ||
| std::format("{:016b}", actual_res)) |
There was a problem hiding this comment.
warning: no member named 'format' in namespace 'std' [clang-diagnostic-error]
std::format("{:016b}", actual_res))
^Additional context
/usr/include/gtest/gtest.h:1897: expanded from macro 'ASSERT_EQ'
#define ASSERT_EQ(val1, val2) GTEST_ASSERT_EQ(val1, val2)
^/usr/include/gtest/gtest.h:1881: expanded from macro 'GTEST_ASSERT_EQ'
ASSERT_PRED_FORMAT2(::testing::internal::EqHelper::Compare, val1, val2)
^/usr/include/gtest/gtest_pred_impl.h:147: expanded from macro 'ASSERT_PRED_FORMAT2'
GTEST_PRED_FORMAT2_(pred_format, v1, v2, GTEST_FATAL_FAILURE_)
^/usr/include/gtest/gtest_pred_impl.h:133: expanded from macro 'GTEST_PRED_FORMAT2_'
GTEST_ASSERT_(pred_format(#v1, #v2, v1, v2), on_failure)
^/usr/include/gtest/gtest_pred_impl.h:78: expanded from macro 'GTEST_ASSERT_'
if (const ::testing::AssertionResult gtest_ar = (expression)) \
^|
|
||
| ASSERT_EQ(std::format("{:016b}", target_res), | ||
| std::format("{:016b}", actual_res)) | ||
| << std::format("sorting failed on binary pattern {} {:016b}", i, i); |
There was a problem hiding this comment.
warning: no member named 'format' in namespace 'std' [clang-diagnostic-error]
<< std::format("sorting failed on binary pattern {} {:016b}", i, i);
^| auto [L, R] = root->Split(key); | ||
| return {SplayTree(L), SplayTree(R)}; | ||
| } | ||
| void SplayTree::Merge(SplayTree&& other) { |
There was a problem hiding this comment.
warning: rvalue reference parameter 'other' is never moved from inside the function body [cppcoreguidelines-rvalue-reference-param-not-moved]
void SplayTree::Merge(SplayTree&& other) {
^|
|
||
| class SplayTree { | ||
| private: | ||
| class SplayTreeNode { |
There was a problem hiding this comment.
warning: constructor does not initialize these fields: key, value [cppcoreguidelines-pro-type-member-init]
task_07/src/tree.hpp:9:
- int key;
- int value;
+ int key{};
+ int value{};| public: | ||
| SplayTree() = default; | ||
| SplayTree(SplayTree const& other) = delete; | ||
| SplayTree(SplayTree&& old); |
There was a problem hiding this comment.
warning: move constructors should be marked noexcept [cppcoreguidelines-noexcept-move-operations]
| SplayTree(SplayTree&& old); | |
| SplayTree(SplayTree&& old) noexcept ; |
| int size; | ||
| int cap; | ||
| int scale; | ||
| const int step_a = 25; |
There was a problem hiding this comment.
warning: member 'step_a' of type 'const int' is const qualified [cppcoreguidelines-avoid-const-or-ref-data-members]
const int step_a = 25;
^| int scale; | ||
| const int step_a = 25; | ||
| int step_b; | ||
| const int default_value; |
There was a problem hiding this comment.
warning: member 'default_value' of type 'const int' is const qualified [cppcoreguidelines-avoid-const-or-ref-data-members]
const int default_value;
^
8 задач
К сожалению, в некоторых местах могут быть неаккуратные названия функций/переменных.